import fetch from "../plugins/request";
import type { paramsLogin, noteNameParams } from "./model/index";
import type { LoginResponseData } from "./types/index";
const dev = import.meta.env.DEV;
console.log(dev, "dev");
const BASEURL = "/api";
const Api = {
  LOGIN: BASEURL + "/login",
  REJISTER: BASEURL + "/register",
  UPLOAD: BASEURL + "/upload",
  PDF: BASEURL + "/getPdf",
  NOTELIST: BASEURL + "/getNoteList",
  SETNOTENAME: BASEURL + "/noteNameUpdate",
  DELNOTE: BASEURL + "/removeNote",
  GETNOTECATE: BASEURL + "/getCate",
  GETCURRENTNOTE: BASEURL + "/getCurrentNote",
  COPYNOTE: BASEURL + "/copyNote",
  SETCURRENTNOTE: BASEURL + "/setCurrentNote",
  GETTEMCATE: BASEURL + "/getTemCate",
  GETTEMLIST: BASEURL + "/getTemList",
  GETTEMDETAILS: BASEURL + "/getTemDetails",
  EDIDPWD: BASEURL + "/editPwd",
  CAPTCHA: BASEURL + "/captcha",
  GETTOKEN: BASEURL + "/robot/getToken",
  TALK: BASEURL + "/robot/talk",
};
//登录
export const login = (data: paramsLogin) => {
  return fetch<LoginResponseData>({
    data,
    url: Api.LOGIN,
    method: "POST",
  });
};
//注册
export const register = (data: paramsLogin) => {
  return fetch({
    data,
    url: Api.REJISTER,
    method: "POST",
  });
};
//上传文件
export const upload = (data: any) => {
  const userInfo: any = uni.getStorageSync("userInfo");
  return new Promise((resolve, inject) => {
    uni.uploadFile({
      url: Api.UPLOAD,
      filePath: data[0],
      formData: {
        filePath: "avatar",
      },
      header: {
        Authorization: "Bearer " + userInfo.token,
      },
      name: "file",
      success: function (uploadRes: any) {
        resolve(JSON.parse(uploadRes.data));
      },
      fail: function (error) {
        inject(error);
      },
    });
  });
};
//生成简历
export const getpdf = (data: any) => {
  return fetch({
    data,
    url: Api.PDF,
    method: "POST",
  });
};
//获取简历列表
export const getNoteList = () => {
  return fetch({
    url: Api.NOTELIST,
  });
};
//设置简历名称
export const setNoteName = (data: noteNameParams) => {
  return fetch({
    data,
    url: Api.SETNOTENAME,
  });
};
//删除简历
export const delNote = (data: noteNameParams) => {
  return fetch({
    data,
    url: Api.DELNOTE,
  });
};
//获取分类
export const getCate = () => {
  return fetch({
    url: Api.GETNOTECATE,
  });
};
//获取当前简历
export const getCurrentNote = () => {
  return fetch({
    url: Api.GETCURRENTNOTE,
  });
};
//复制简历
export const toCopyNote = (data: any) => {
  return fetch({
    data,
    url: Api.COPYNOTE,
    method: "POST",
  });
};
//设置当前简历
export const setCurrentNote = (data: any) => {
  return fetch({
    data,
    url: Api.SETCURRENTNOTE,
  });
};
//获取简历模板分类
export const getTemCate = () => {
  return fetch({
    url: Api.GETTEMCATE,
  });
};
//获取模板列表
export const getTemList = (data: any) => {
  return fetch({
    url: Api.GETTEMLIST,
    data,
  });
};

//获取简历详情
export const getTemDetails = (data: any) => {
  return fetch({
    url: Api.GETTEMDETAILS,
    data,
  });
};

//修改密码
export const editPwd = (data: any) => {
  return fetch({
    url: Api.EDIDPWD,
    data,
    method: "POST",
  });
};

/** 条形码 */
export function getCaptcha() {
  return fetch({
    url: Api.CAPTCHA,
  });
}

/** 获取wx token */
export function getToken() {
  return fetch({
    url: Api.GETTOKEN,
  });
}

/** 和wx robot 对话 */
export function wxTalk(data: any) {
  return fetch({
    url: Api.TALK,
    data,
  });
}
